// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <gtest/gtest.h>
#include <sstream>
#include "melon/conv.h"
#include <pollux/vector/type_aliases.h>

namespace kumo::pollux {

// Forward declaration, which is defined in ComplexVector.cpp
std::string stringifyTruncatedElementList(
    vector_size_t start,
    vector_size_t size,
    vector_size_t limit,
    std::string_view delimiter,
    const std::function<void(std::stringstream&, vector_size_t)>&
        stringifyElementCB);

namespace {
TEST(ToStringUtil, stringifyTruncatedElementList) {
  const auto indexAsString = [](std::stringstream& ss, vector_size_t i) {
    ss << melon::to<std::string>(i);
  };

  // no item
  EXPECT_EQ(
      stringifyTruncatedElementList(0, 0, 0, ", ", indexAsString), "<empty>");
  // exact item
  EXPECT_EQ(
      stringifyTruncatedElementList(0, 5, 5, ", ", indexAsString),
      "5 elements starting at 0 {0, 1, 2, 3, 4}");
  // more items
  EXPECT_EQ(
      stringifyTruncatedElementList(1, 3, 2, ", ", indexAsString),
      "3 elements starting at 1 {1, 2, ...}");
  // less items
  EXPECT_EQ(
      stringifyTruncatedElementList(1, 3, 5, ", ", indexAsString),
      "3 elements starting at 1 {1, 2, 3}");
  // zero limit.
  EXPECT_EQ(
      stringifyTruncatedElementList(1, 5, 0, ", ", indexAsString),
      "5 elements starting at 1 {...}");
  // different delimiter
  EXPECT_EQ(
      stringifyTruncatedElementList(0, 3, 5, "<delimiter>", indexAsString),
      "3 elements starting at 0 {0<delimiter>1<delimiter>2}");
}
} // namespace
} // namespace kumo::pollux
